# ecshop操作封装https://ecshop.test2.shopex123.com/
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By


class ECShop:
    username = "Frankly"
    password = "123@abc"
    email = "315@qq.com"

    def __init__(self):
        self.chrome = webdriver.Chrome()
        self.chrome.get("https://ecshop.test2.shopex123.com/")
        self.chrome.maximize_window()
        sleep(3)

    def search(self):
        self.chrome.find_element(By.ID, "keyword").send_keys("屈臣氏")
        sleep(2)
        self.chrome.find_element(By.CLASS_NAME, "btn_search").click()
        sleep(2)

    def register(self):
        self.chrome.find_element(By.PARTIAL_LINK_TEXT, "注册").click()
        sleep(2)
        self.chrome.find_element(By.ID, "username").send_keys(self.username)
        self.chrome.find_element(By.ID, "email").send_keys(self.email)
        for e in self.chrome.find_elements(By.XPATH, "//input[contains(@id, 'password')]"):
            e.send_keys(self.password)
        sleep(3)
        self.chrome.find_element(By.XPATH, "//input[@name='Submit' and @class='signup_button']").click()
        sleep(5)

    def login(self):
        self.chrome.find_element(By.XPATH, "//a[contains(text(), '登录')]").click()
        sleep(2)
        self.chrome.find_element(By.XPATH, "//form//input[@name='username']").send_keys(self.username)
        self.chrome.find_element(By.XPATH, "//form//input[@name='password']").send_keys(self.password)
        sleep(3)
        self.chrome.find_element(By.XPATH, "//form//input[@name='submit']").click()
        sleep(5)


if __name__ == '__main__':
    ec_shop = ECShop()
    # ec_shop.search()
    # ec_shop.register()
    ec_shop.login()
